//
// Created by liushuai on 2021/2/26.
//

#include "repeatedSubstringPattern.h"
bool repeatedSubstringPattern(string s) {
    int length = s.size();
    bool res = false;
    set<string> subset;

    for(int i=1;i<=length/2;i++){
        if (length%i == 0){
            int seg_length = i;
            int seg_num = length/i;
            string current = s.substr(0,seg_length);
            string next;
            int j = 0;
            for(;j<seg_num-1;j++){
                int start = (j+1)*seg_length;
                next = s.substr(start,seg_length);
                if(current == next){
                    current == next;
                } else
                    break;
            }
            if(current == next)
                res = true;

        }
    }
    return res;
}
bool repeatedSubstringPattern1(string s){
    return (s+s).find(s,1)!=s.size();
}